\documentclass[11pt,letterpaper]{article}

\usepackage[top=2.5cm,left=3cm,right=3cm,foot=.5cm,bottom=2.5cm]{geometry} \geometry{letterpaper} % or letter or a5paper or ... etc\usepackage{setspace}

\usepackage{color}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{array}
\usepackage{float}
\usepackage{booktabs}
\usepackage{dcolumn}

\renewcommand{\thesubsection}{\Alph{subsection}}
\renewcommand{\thetable}{\Alph{subsection}\arabic{table}}
\renewcommand{\thefigure}{\Alph{subsection}\arabic{figure}}


\title{\textbf{Online Supplement:} From Protest to Ideology: How Social Movements Reshape Political Orientations Over Time}

\author{Matías Bargsted, Nicolás Somma, Ignacio Cáceres, Camila Ortiz-Inostroza \& \\Roberto González.}
\date{May, 2025}

\begin{document}

\maketitle{}

\appendix


\subsection{Introduction}

The following document provides details about measurement, replication code, and full empirical results. These entail:
\begin{itemize}
  \item Details about measurement and construction of all the variables involved in the analysis (section B).
  \item Description of the multiple imputation procedure implemented to deal with the missing data problem in the dependent variable (section C).
	\item Estimates from dynamic linear models with and without multiple imputation and varying specifications (section D).
	\item Details on procedures and results of robustness checks (section E).
\end{itemize}


\subsection{Measurement of Variables}

Details about how the independent and dependent variables were measured are provided below:

\paragraph{Ideological preferences:} ``Changing the topic, traditionally in our country people define their political position as being closer to the left, to the center or to the right. Using a scale from 0 to 10 where 0 is on the `left', 5 is on the `center' and 10 is on the `right', where do you place yourself on this scale? Indicate which number best describes you''. 

\paragraph{Social Movement Assessment:} ``Considering the list of social movements that I will now show you, please indicate which one you value the most''.
\begin{itemize}
	\item[] 1. Social movement that supports the student cause.
	\item[] 2. Social movement that supports labor demands.
	\item[] 3. Social movement of environmentalist groups.
	\item[] 4. Social movement that supports indigenous demands.
	\item[] 5. Social movement that supports sexual diversity.
	\item[] 6. Social movement that is pro-life or anti-abortion.
	\item[] 7. Social movement against crime.
	\item[] 8. Feminist or supporting gender equality social movement (from wave 2018 onwards).
	\item[] 9. Social movement for the change of retirement system (from wave 2018 onwards).
	\item[] 10. Social movement of October (18/O) (from wave 2019 onwards).
	\item[] Other, Specify.
	\item[] None (do not read).
	\item[] Does not know (do not read).
	\item[] Does not respond (do not read).
\end{itemize} 

We recoded responses 1 to 5 and 8 to 10 as indicative of supporting a progressive social movement (coded as 1). Conversely, responses 6 and 7, as well as the option `None' were recoded as not supporting a progressive social movement (coded as 0). Verbatim responses  within the `Other' category were also recoded as 1 if the indicated movement was also progressive. 

\paragraph{Political Interest:} ``How interested are you in politics?'' Ordinal response categories that range from `Not interested' (coded with 1) to `Very interested' (coded with 5).

\paragraph{Church attendance:} ``How often do you attend religious services?''. Ordinal response categories that range from `Several times a week' (coded with 1) to `Never or almost never' (coded with 7). Respondents self identified as atheist and agnostics were coded with the first response category.

\paragraph{Unemployed occupational status:} ``Which of these situations best describes your main activity during last month?''. People who were unemployed or looking for a job were coded with 1, while all other categories including students, full-time and part-time paid workers, retirees, unpaid workers and remaining options were designated as the reference category (coded with 0).  

\paragraph{Subjective Social Status:}  ``In our society, there are groups that tend to place themselves at the higher levels and groups that tend to place themselves at the lower levels of society. Using the scale provided, where 0 is the lowest level and 10 is the highest level, where would you place yourself in Chilean society?'' Ordinal response scale that ranges from 0 to 10.

\medskip
\medskip
\medskip

Additionally, we employed a set of variables to perform a multiple imputation of the missing data in the dependent variable. These variables are the following:

\paragraph{Male:} A dummy variable that identifies males.

\paragraph{Age:} Age in years introduced as a continuous variable.

\paragraph{Education:} ``What is your educational level?''. A set of dummy variables created from the original 10 response categories: ‘primary complete or less’, ‘secondary incomplete’, ‘secondary complete’, ‘tertiary technical’ and ‘university’.

\paragraph{Vote intention on 2017 presidential election:} ``Regarding the presidential election next November, for which of the following candidates will you vote? Or will you not attend to vote?'' Three dummy variables were created, identifying the main candidates' vote intention: Sebastian Piñera, Alejandro Guillier, and Beatriz Sanchez. All other responses are left as reference category.

\paragraph{Authoritarianism:} A composite index of authoritarianism was created using four 1-5 response items: ``Instead of so much concern for the rights of the people, what this country needs is a strong government'', ``What our country needs is a strong leader with the determination to lead us on the right path'', ``Obedience and respect for authority are the most important values that children should learn'' and, ``The true keys to having a good life are obedience and discipline.'' The resultant variable represents the average score in these four items for each person in each wave, ranging from 1 to 5 (high values indicate greater agreement with sentences).

\paragraph{Police use of force:} Two five-point ordinal response items were used to construct an index of justification of the police use of force. The questions are: ``To what extent do you think the following situations are justified or unjustified?: That police uses the force to suppress a peaceful protest'', and ``That police forcibly evict students from an occupied high school''. Both items were averaged, resulting in a variable ranging from 1 to 5 (high values indicate higher justification).

\paragraph{Trust in the police:} A five-point ordinal response item ranging from `Nothing' to  `A lot' with the question: ``And regarding the following institutions, how much do you trust...?''. Code 5 was recoded as 4 to avoid levels with very few observations. 

\medskip

<<echo=FALSE, results='asis', warning=FALSE, message=FALSE, cache=F>>=
rm(list=ls())
options(scipen=999)
options(max.print=1000000)

#Set your working directory
#setwd()

#Original dataset in wide format
elsoc_wide<-url("https://dataverse.harvard.edu/api/access/datafile/6160174")
load(elsoc_wide)

#Recodification and generation of long and wide datasets
source("recodification.R")

library(tidyverse)
library(car)
library(psych)
library(lmtest)
library(plm)
library(panelr)
library(lme4)
library(sandwich)
library(AER)
library(texreg)
library(fBasics)
library(kableExtra)
library(survey)
library(MCMCglmm)
library(mice)
library(mitools)
library(miceadds)
library(ggplot2)
library(Hmisc)
library(ggpubr)
library(xfun)
library(dpm)

##Descriptive statistics

#Subset of respondents with at least one answer in left-right scale
#c <- ave(ell$izqder, ell$idencuesta, FUN = function(x) mean(x, na.rm=T))
#ell <- subset(ell, subset=!is.nan(c))

#Recoding education
ell$ed_basica<-as.numeric(as.character(car::recode(ell$educF,"'Ed. Basica o menos'=1; else=0")))
ell$ed_media<-as.numeric(as.character(car::recode(ell$educF,"'Ed. Media Inc.'=1; else=0")))
ell$ed_mediac<-as.numeric(as.character(car::recode(ell$educF,"'Ed. Media Com.'=1; else=0")))
ell$ed_tecsup<-as.numeric(as.character(car::recode(ell$educF,"'Ed. Tec. Sup.'=1; else=0")))
ell$ed_univ<-as.numeric(as.character(car::recode(ell$educF,"'Ed. Univer.'=1; else=0")))


#Table B1: Descriptive statistiscs of the original dataset
tab1=as.data.frame(select(ell, izqder,mov_izq, practica,desempleo,ess,InteresPoli,
                          hombre, edad, ed_basica, ed_media, ed_mediac,ed_tecsup, 
                          ed_univ, int_Guillier02, int_Pinera02, int_Sanchez02, 
                          autori,ViolCarab,confCara)); tab1=tab1[,-c(1:2)]
tab1=as.data.frame(t(basicStats(tab1))); tab1$propNA=tab1$NAs*100/tab1$nobs
tab1=tab1[c(1,17,3:4,7:8,14)]
tab1[,5:7] <- round(tab1[,5:7], digits = 2); tab1[,2] <- round(tab1[,2], digits = 1)
rownames(tab1)<-c("Left-Right Scale", "Social Movement Assessment","Church Attendance",
                  "Unemployed", "Subjective Social Status", "Political Interest",
                  "Male", "Age", "Primary Ed.", "Incomplete Secondary Ed.", 
                  "Complete Secondary Ed.", "Technical Terciary Ed.", "University Ed.", 
                  "Vote Intention for Guillier", "Vote intention for Piñera", 
                  "Vote Intention for Sanchez", "Authoritariarism",
                  "Use of Police Force", "Trust in the Police")

kbl(tab1, booktabs = T, 
    col.names = c("Obs", "% NA", "Min", "Max","Mean","Median","SD"),
    caption = "Descriptive Statistiscs of the Original Dataset",) %>% 
  kable_styling(latex_options = c("center", "HOLD_position"))%>%
  pack_rows("Analysis model", 1, 6) %>%
  pack_rows("Imputation model", 7, 19) %>%
  footnote(general = "Data in long format. Observations from 1513 individuals measured across 5 waves.")
@


\subsection{Multiple Imputation}

\subsubsection{Procedure}

The size of the original sample in the first wave was 2927. Given sample attrition, it decreased to 2473 in 2017, 2229 in 2018, 2153 in 2019, and 1739 in 2021 (this sharpest decline occurred during the last wave, presumably due to the pandemic context). From these 1739 cases, we selected only those respondents who participated in all survey waves, resulting in a final balanced sample size of 1513 respondents and 7565 observations.
\medskip

Many survey respondents did not answer the left-right ideological self-placement scale in all survey waves. In fact, as it is shown in table B1, 36\% of all responses did not provide a self-placement on the scale. People who did not express ideological self-placement in some waves are significantly less engaged with political affairs (less interested in politics, turnout at lower rates, talks less about politics offline and online), tend to be less educated, and are more likely to be religious than people who express an ideological placement (Bargsted and Somma 2016; Zechmeister and Corral 2013). Consequently, by simply dropping these observations from the analysis, we risk biasing the sample, and estimates, toward the direction of more politically involved, educated, and secular people.
\medskip

Due to the risks associated with list-wise deletion, we decided to recover the missing responses using multiple imputation. From the sample of 1513 individuals measured in five waves (7565 observations), respondents who declined to place themselves on the scale during all five panel waves (5\%) were excluded from the analysis. The resulted in a dataset composed of 1434 respondents and 7170 observations. Using this data, we compute the percentage of missing data in the dependent variable for each of the five ELSOC panel waves, as shown in table C1.

\medskip
  

\setcounter{table}{0} %%Renew count of tables

<<echo=FALSE, eval=TRUE, results='asis', warning=FALSE, message=FALSE, cache=F>>=
########
#Select sample 1
elw <- subset(elw, muestra==1)
#Select data without attrition
elw=filter(elw, tipo_atricion==1)
#Exclude cases whitout ideological self-position in any wave
elw = filter(elw, !is.na(izqder_w01)|!is.na(izqder_w02)|!is.na(izqder_w03)| 
               !is.na(izqder_w04)|!is.na(izqder_w05))

#Nuber of NA in DV for each wave
NA_w1 = round(sum(is.na(elw$izqder_w01))*100/nrow(elw),1) #41.8
NA_w2 = round(sum(is.na(elw$izqder_w02))*100/nrow(elw),1) #39.3
NA_w3 = round(sum(is.na(elw$izqder_w03))*100/nrow(elw),1) #27.7
NA_w4 = round(sum(is.na(elw$izqder_w04))*100/nrow(elw),1) #32.7
NA_w5 = round(sum(is.na(elw$izqder_w05))*100/nrow(elw),1) #21.2


#Table C1: Percentage of missing data on Left-Right Ideological Scale
tab2= as.data.frame(cbind(NA_w1, NA_w2, NA_w3, NA_w4, NA_w5))
tab2[2,] = as.character(c(rep(1434, 5)))
colnames(tab2)=c("Wave 1", "Wave 2", "Wave 3", "Wave 4","Wave 5")
rownames(tab2)=c("% Missing Obs.", "N Obs.")

kbl(tab2, booktabs = T, 
    caption = "Percentage of missing data on Left-Right Ideological Scale") %>% 
  kable_styling(latex_options = c("center", "HOLD_position"))
@
\medskip

We impute missing observations from the dependent variable following two key recommendations from the specialized literature. In the first place, it is convenient to have highly predictive auxiliary variables that add information to the imputation process model but that are later excluded from the analytical model (Von Hippel, 2007; Honaker \& King, 2010). The inclusion of these variables also helps make the missing at random (MAR) assumption more plausible (Hardt et al., 2012). Second, the literature suggests that when panel data is available adding lags and/or leads of the imputed variable as predictors helps to increase the imputation model’s predictive capacity (Austin et al. 2021; Honaker and King 2010). 

Based on these considerations, we constructed an imputation model which includes auxiliary variables, outcome lags, and analysis model variables. These are detailed below:

\begin{itemize}
\item Auxiliar variables: presidential vote intention 2017, authoritarism Index, trust in police index, police violence justification index.
\item Analysis model variables: social movement assessments (lagged and contemporaneous), age, gender, education, church attendance, unemployment, subjective social status. 
\item Lagged ideological left-right self-position (dependent variable)
\end{itemize}

Based on these variables we imputed the missing observations of all respondents who self-positioned themselves in the left-right ideological scale at least once using Iterated Chain Equations implemented through the MICE package (van Bureen, 2011) in R software. The imputation employed predictive mean matching algorithm with 100 iterations. Parameter estimates are based on ten completed samples.

<<echo=FALSE, eval=TRUE, results='hide', warning=FALSE, message=FALSE, cache=F, error=FALSE>>=

#Imputation model
#wave 1
modimp1 <-lm(izqder_w01~
               mov_izq_w01+practica_w01+ess_w01+desempleo_w01+InteresPoli_w01+ #analysis mod
               int_Guillier02+int_Pinera02+int_Sanchez02+autori_w01+ViolCarab_w01+#imputation mod,
               confCara_w01+hombre_w01+edad_w01+educF_w01,#imputation mod
             data=elw)
#wave 2
modimp2 <-lm(izqder_w02~
               mov_izq_w02+practica_w02+ess_w02+desempleo_w02+InteresPoli_w02+#analysis mod
               int_Guillier02+int_Pinera02+int_Sanchez02+autori_w02+ViolCarab_w02+#imputation mod,
               confCara_w02+hombre_w01+edad_w01+educF_w01+#imputation mod,
               izqder_w01+mov_izq_w01,#lags
               data=elw)#vars mod imput
#wave 3
modimp3 <-lm(izqder_w03~
               mov_izq_w03+practica_w03+ess_w03+desempleo_w03+InteresPoli_w03+#analysis mod
               int_Guillier02+int_Pinera02+int_Sanchez02+autori_w03+ViolCarab_w03+#imputation mod,
               confCara_w03+hombre_w01+edad_w01+educF_w01+#imputation mod,
               izqder_w02+mov_izq_w02,#lags
               data=elw)#vars mod imput
#wave 4
modimp4 <-lm(izqder_w04~
               mov_izq_w04+practica_w04+ess_w04+desempleo_w04+InteresPoli_w04+#analysis mod
               int_Guillier02+int_Pinera02+int_Sanchez02+autori_w04+ViolCarab_w04+#imputation mod,
               confCara_w04+hombre_w01+edad_w01+educF_w01+#imputation mod,
               izqder_w03+mov_izq_w03,#lags
               data=elw)#vars mod imput
#wave 5
modimp5 <-lm(izqder_w05~
               mov_izq_w05+practica_w05+ess_w05+desempleo_w05+InteresPoli_w05+#analysis mod
               int_Guillier02+int_Pinera02+int_Sanchez02+autori_w05+ViolCarab_w05+#imputation mod,
               confCara_w05+hombre_w01+edad_w01+educF_w01+#imputation mod,
               izqder_w04+mov_izq_w04,#lags
             data=elw)#vars mod imput

screenreg(list(modimp1,modimp2,modimp3,modimp4,modimp5), single.row = T,
          custom.model.names = c("MI1","MI2","MI3","MI4","MI5"))
@

<<echo=FALSE, eval=TRUE, warning=FALSE, results='hide',message=FALSE, cache=T, error=FALSE>>=

#Multiple Imputation

vars<-c("izqder_w01","izqder_w02","izqder_w03","izqder_w04","izqder_w05",
        "mov_izq_w01","mov_izq_w02","mov_izq_w03","mov_izq_w04","mov_izq_w05",
        "edad_w01","hombre_w01","educF_w01","practica_w01","practica_w02",
        "practica_w03","practica_w04","practica_w05", 
        "int_Guillier02","int_Pinera02","int_Sanchez02",
        "autori_w01","ViolCarab_w01","confCara_w01",
        "autori_w02","ViolCarab_w02","confCara_w02",
        "autori_w03","ViolCarab_w03","confCara_w03",
        "autori_w04","ViolCarab_w04","confCara_w04",
        "autori_w05","ViolCarab_w05","confCara_w05",
        "InteresPoli_w01","InteresPoli_w02","InteresPoli_w03",
        "InteresPoli_w04","InteresPoli_w05","idencuesta",
        "desempleo_w01","desempleo_w02","desempleo_w03",
        "desempleo_w04","desempleo_w05","ess_w01","ess_w02",
        "ess_w03","ess_w04","ess_w05",paste0("polengage_w0",1:5))

elw_miss <- elw[, names(elw) %in% vars]
elw_miss$imputed <- ifelse(is.na(elw_miss$izqder_w01), 1, 0)

#Set up imputation process
imp <- mice(elw_miss, maxit = 0)
predmat <- imp$predictorMatrix #imputation matrix
for(i in 1:dim(predmat)[1]) predmat[i,] = 0
  
ivs1 <- c("edad_w01","hombre_w01","educF_w01", "int_Guillier02",
          "int_Pinera02", "int_Sanchez02")
ivs2 <- c("practica_w","InteresPoli_w", "mov_izq_w","desempleo_w",
          "ess_w", "confCara_w", "ViolCarab_w", "autori_w")

predmat["izqder_w01",c(ivs1,paste0(ivs2,"01"))]=1; 
predmat["izqder_w02",c(ivs1,paste0(ivs2,"02"),"izqder_w01","mov_izq_w01")]=1
predmat["izqder_w03",c(ivs1,paste0(ivs2,"03"),"izqder_w02","mov_izq_w02")]=1
predmat["izqder_w04",c(ivs1,paste0(ivs2,"04"),"izqder_w03","mov_izq_w03")]=1
predmat["izqder_w05",c(ivs1,paste0(ivs2,"05"),"izqder_w04","mov_izq_w04")]=1

meth = imp$method
for(i in 1:length(meth)) meth[i] = ""
meth["izqder_w01"] = "pmm"
meth["izqder_w02"] = "pmm"
meth["izqder_w03"] = "pmm"
meth["izqder_w04"] = "pmm"
meth["izqder_w05"] = "pmm"

#Force values of imputed izq-der within 0-10 range
post <- imp$post
post["izqder_w01"] <- "imp[[j]][, i] <- squeeze(imp[[j]][, i], c(0, 10))"
post["izqder_w02"] <- "imp[[j]][, i] <- squeeze(imp[[j]][, i], c(0, 10))"
post["izqder_w03"] <- "imp[[j]][, i] <- squeeze(imp[[j]][, i], c(0, 10))"
post["izqder_w04"] <- "imp[[j]][, i] <- squeeze(imp[[j]][, i], c(0, 10))"
post["izqder_w05"] <- "imp[[j]][, i] <- squeeze(imp[[j]][, i], c(0, 10))"

#Impute
imp1 <- mice(elw_miss, m=10, meth=meth, pred=predmat, maxit = 100,
             post=post, seed=4826)
save(imp1, file="imp1.Rdata")

##Create and save completed Data Frame
elw_comp <- mice::complete(imp1, "long", include=F)
save(elw_comp, file="Elsoc_Wide_2016_2021_completed.Rdata")
@
\medskip

Variables selected to impute the left-right ideological scale explain above 40\% of the dependent variable variance, except for wave 1, which did not include lags of ideological scale nor social movement assessments. We could recover almost all the missing values, remaining between 0.3\% and 0.7\% of missingness in imputed data per wave, as shown in table C2.

<<echo=FALSE, results='asis', warning=FALSE, message=FALSE, cache=F>>=

#Table C2: Imputation model results
mods<-list(modimp1,modimp2,modimp3,modimp4,modimp5)
r2s<-as.character(round(sapply(mods, function(x) summary(x)$adj.r.squared),2))

na_imp <- elw_comp %>% 
  summarise(na_w1_imp = round((sum(is.na(izqder_w01)))*100/14340, 1),
            na_w2_imp = round((sum(is.na(izqder_w02)))*100/14340, 1),
            na_w3_imp = round((sum(is.na(izqder_w03)))*100/14340, 1),
            na_w4_imp = round((sum(is.na(izqder_w04)))*100/14340, 1),
            na_w5_imp = round((sum(is.na(izqder_w05)))*100/14340, 1))
tab3=rbind(r2s,na_imp)
colnames(tab3)=c("Wave 1", "Wave 2", "Wave 3", "Wave 4","Wave 5")
rownames(tab3)=c("Adjusted R-Squared", "% Missing Obs.")

kbl(tab3, booktabs = T, 
    caption = "Imputation model results") %>% 
  kable_styling(latex_options = c("center", "HOLD_position"))
@

\medskip
\subsubsection{Diagnostics}
\medskip
To check if the imputation process generated reasonable values, we assessed the discrepancy between observed and imputed data. Figure C1 shows density plots of left-right self-placement for five waves included in the analysis.  

\medskip
As the density plots show, the distribution patterns of imputed data (red lines) are similar to that of the original data (blue line), and no systematic discrepancies are observed. Consequently, the assumption that imputed values could have been real and observed values seems reasonable.

\setcounter{table}{0} %%Renew count of tables
\setcounter{figure}{0}

<<echo=FALSE, eval=TRUE, results='asis', warning=FALSE, message=FALSE, cache=F, fig.pos="H", fig.cap="Density Plots for Original and Imputed Data", out.width="80%", fig.align ='center'>>=
load("imp1.Rdata")

#Figure 1: 
#All combined in one panel per wave
dp1<-densityplot(imp1, ~izqder_w01, xlab="", ylab="", main=list("Wave 1", cex=1, font=1, x=.5))
dp2<-densityplot(imp1, ~izqder_w02, xlab="", ylab="", main=list("Wave 2", cex=1, font=1,x=.5))
dp3<-densityplot(imp1, ~izqder_w03, xlab="", ylab="", main=list("Wave 3", cex=1, font=1,x=.5))
dp4<-densityplot(imp1, ~izqder_w04, xlab="", ylab="", main=list("Wave 4", cex=1, font=1,x=.5))
dp5<-densityplot(imp1, ~izqder_w05, xlab="", ylab="", main=list("Wave 5", cex=1, font=1,x=.5))

figD1<-ggarrange(dp1,dp2,dp3,dp4,dp5, ncol = 2, nrow=3)

annotate_figure(figD1, left = textGrob("Density", rot = 90, vjust = 1, gp = gpar(cex = 1.1)),
                    bottom = textGrob("Left-right self-placement", gp = gpar(cex = 1.1)))
@

\newpage
\subsection{Estimates from Linear Dynamic Panel Models (Arellano Bond Difference Models)}

\setcounter{table}{0} %%Renew count of tables
\setcounter{figure}{0}

<<echo=FALSE, eval=TRUE, results='hide', warning=FALSE, message=FALSE, cache=T>>=

#Subset of respondents with at least one answer in left-right scale
c <- ave(ell$izqder, ell$idencuesta, FUN = function(x) mean(x, na.rm=T))
ell <- subset(ell, subset=!is.nan(c))

#Function to extract imputed pgmm models pgmm with 'texreg'
source("extract_pgmm_mi.R")
source("pgmm_summary_fix.R")

#Create an imputationList by splitting the tall dataset by imputation id
imp_list <- imputationList(split(elw_comp, elw_comp$.imp))

#Wide to long
vv <- c("practica","desempleo", "confCara", "ViolCarab","InteresPoli", 
        "polengage", "izqder", "autori", "mov_izq", "ess")
imputations <-lapply(imp_list$imputations, function(df) {
  reshape(df, varying=lapply(vv, function(x) paste0(x,"_w0", 1:5)),
          v.names = vv, direction="long", idvar="idencuesta", times=1:5)})
imp_long <- list(imputations); names(imp_long) <- c("imputations")
@


<<echo=FALSE, eval=FALSE, results='hide', warning=FALSE, message=FALSE, cache=T>>=

### Code for Figure 1,  Main Article ###

#A. Positive assessment of Social Movement by Year and Ideological Family

#Original Data
load("Elsoc_Long_2016_2021_REC.Rdata")
#Subset 2 olas minimo
ell <- subset(ell, muestra==1 & tipo_atricion==1)

aa <- data.frame(prop.table(with(ell, wtd.table(mov_ideo, time, weights=ponderador02)), 2))
names(aa) <- c("mov_ideo", "time", "Freq")
levels(aa$mov_ideo) <- c("Conservative \nMovements\n", "Progressive \nMovements\n", 
                         "Mentions No \nMovement\n", 
                         "Other \nMovements\n")

p1 <- ggplot(aa, aes(time, Freq, group=mov_ideo, shape=mov_ideo)) + 
  geom_point(size=2) + geom_line() + ylim(0,1) +
  theme_bw() + 
  labs(y="% Positive Assessments", x="Year",
       title="A) Positive Assessments of Social Movement by \nYear and Ideological Family") +
  scale_shape_manual(name = "Ideological \nFamily:", values = c(15:17,8)) + 
  scale_x_discrete(labels=c('2016', '2017', '2018', "2019", "2020/1")) + 
  theme(legend.spacing.x = unit(.05, 'cm'))  
p1


#B. Positive Assessment of Progressive Movements by Year and Respondent Ideology in Wave 1

library(data.table)
ell <- setDT(ell)
ell[, izqderF_w01:=izqderF[1], by=idencuesta]
ell[, year:=time+2015]
table(ell$izqderF_w01, ell$year)

mm <- ell[, weighted.mean(mov_izq, ponderador02), by=.(year, izqderF_w01)]
names(mm) <- c("year", "group_ideo", "prop_support")
levels(mm$group_ideo) <- c("Left", "Center", "Right", "None or \nIndependent")
mm$year <- factor(mm$year)
levels(mm$year)

p2 <- ggplot(mm, aes(year, prop_support, group=group_ideo, shape=group_ideo )) + 
  geom_point(size=2) + geom_line() + ylim(0,1) +
  theme_bw() + scale_shape_manual(name = "Ideology \nin Wave 1:", values = c(15:17,8)) +
  #scale_x_discrete(labels=c('2016', '2017', '2018', "2019", "2020/1")) +
  theme(legend.spacing.x = unit(.05, 'cm')) +
  labs(y="% Positive Assessments of \nProgresive Movements",
       x="Year",
       title="B) Positive Assessments of Progressive Movements \nby Year and Respondent Ideology in Wave 1") +
  scale_x_discrete(labels=c('2016', '2017', '2018', '2019', '2020/1'))

##Combine PLot 1 and 2
library(ggpubr)
ggarrange(p1, p2, ncol = 2, nrow = 1)
@

\subsubsection{Linear Dynamic Models for Political Ideology under Sequential Exogeneity}
  
<<echo=FALSE, eval=TRUE, results='asis', warning=FALSE, message=FALSE,  cache=T, fig.pos='H'>>=

#Arellano Bond 1 - lag Social Movements Assessment (original data)
ab1_cm <-pgmm(izqder ~ lag(izqder,1) + lag(mov_izq,1) + ess + desempleo + practica + InteresPoli | 
                lag(izqder, 2:99) + lag(mov_izq, 2:99), 
              data = ell, index = c("idencuesta","time"), 
              effect="twoways", transformation="d", model="onestep")

#Arellano Bond 1 - lag Social Movements Assessment (imputed data)
ab1_imp <- lapply(imp_long$imputations, function(x){
  pgmm(izqder ~ lag(izqder,1) + lag(mov_izq,1) + ess + desempleo + practica + InteresPoli | 
         lag(izqder, 2:99) + lag(mov_izq, 2:99), 
       data = x, index = c("idencuesta","time"), 
       effect="twoways", transformation="d", model="onestep")})

#Arellano Bond 2 - Contemporaneous Social Movements Assessment (original data)
ab2_cm <-pgmm(izqder ~ lag(izqder,1) + mov_izq + ess + desempleo + practica + InteresPoli | 
                lag(izqder, 2:99) + lag(mov_izq, 1:99), 
              data = ell, index = c("idencuesta","time"), 
              effect="twoways", transformation="d", model="onestep")

#Arellano Bond 2 - Contemporaneous Social Movements Assessment (imputed data)
ab2_imp <- lapply(imp_long$imputations, function(x){
  pgmm(izqder ~ lag(izqder,1) + mov_izq + ess + desempleo + practica + InteresPoli | 
         lag(izqder, 2:99) + lag(mov_izq, 1:99), 
       data = x, index = c("idencuesta","time"), 
      effect="twoways", transformation="d", model="onestep")})

#Arellano Bond 3 - Lagged and Contemporaneous Social Movements Assessment (original data)
ab3_cm <-pgmm(izqder ~ lag(izqder,1) + mov_izq + lag(mov_izq,1) + ess + desempleo + 
               practica + InteresPoli | 
               lag(izqder, 2:99) + lag(mov_izq, 1:99) + lag(mov_izq, 2:99), 
             data = ell, index = c("idencuesta","time"), 
             effect="twoways", model="onestep", transformation = "d")

#Arellano Bond 3 - Lagged and Contemporaneous Social Movements Assessment (imputed data)
ab3_imp <- lapply(imp_long$imputations, function(x){
  pgmm(izqder ~ lag(izqder,1) + mov_izq + lag(mov_izq,1) + ess + desempleo + 
         practica + InteresPoli | 
         lag(izqder, 2:99) + lag(mov_izq, 1:99) + lag(mov_izq, 2:99), 
       data = x, index = c("idencuesta","time"), 
       effect="twoways", model="onestep", transformation = "d")})

texreg(l=list(extract.pgmm_R(ab1_cm),extract.pgmm_R(ab2_cm),extract.pgmm_R(ab3_cm), 
             extract.pgmm_mi(ab1_imp),extract.pgmm_mi(ab2_imp),extract.pgmm_mi(ab3_imp)),
       custom.model.names = c("1","2","3","4","5","6"),
       custom.header = list("Without MI"=1:3,"With MI"=4:6),
       dcolumn = T, booktabs = T, use.packages = F,
       scalebox = .8, float.pos = "H", digits=3,
       include.wald=F, include.wald.td=F,
       custom.coef.map=list("lag(izqder, 1)"="Left-Right Scale$_{t-1}$", 
                              "lag(mov_izq, 1)"="Social Movement Assessment$_{t-1}$", 
                              "mov_izq"="Social Movement Assessment$_{t}$", 
                              "ess"="Subjective Social Status$_{t}$", 
                              "desempleo"="Unemployed$_{t}$",
                              "practica"="Church Attendance$_{t}$", 
                              "InteresPoli"="Political Interest$_{t}$",
                              "3"="Wave 2018", "4"="Wave 2019", "5"="Wave 2020/1"),
       custom.note = "%stars. Standard errors in parentheses. MI = Multiple imputation.",
       caption="Dynamic Panel Models (Arellano-Bond Estimator) for Left-Right Self-Placement, Under Sequential Exogeneity. Original and Imputed Data.")
@
  
\newpage
    
\subsubsection{Linear Dynamic Models for Political Ideology under Sequential Exogeneity and Moderated by Political Interest}

Before estimating the panel models moderated by political interest, we calculated the average political interest for individuals in the sample through the five waves. The distribution of average values is displayed in Figure D1. As can be seen, average levels of political interest are markedly biased toward low values. Considering this, we decided to perform the moderation analysis by dividing the sample into two groups around the percentile 75. Consequently, we got, as a result, a first group of `low interest' comprised of individuals whose means are between 1 and 2.4 and a `high interest' group, composed of those who have an average political interest from 2.5 to 5.

\medskip
\medskip
<<echo=FALSE, eval=TRUE, warning=FALSE, message=FALSE, cache=TRUE>>=

#Recode Political Interest - Observed Data
ell$InteresPoli_av <- ave(ell$InteresPoli, ell$idencuesta, na.rm=T)
ell$InteresPoli_avF <- cut(ell$InteresPoli_av, include.lowest=TRUE,
                             breaks=quantile(ell$InteresPoli_av, c(0,.75,1)))
levels(ell$InteresPoli_avF) <- c("Low", "High")

#Recode Political Interest - Imputed Data
for(i in 1:length(imp_long$imputations)) {
  imp_long$imputations[[i]]$InteresPoli_av <- ave(imp_long$imputations[[i]]$InteresPoli,
                                                  imp_long$imputations[[i]]$idencuesta, 
                                                    na.rm=T)
}
for(i in 1:length(imp_long$imputations)) {
  imp_long$imputations[[i]]$InteresPoli_avF <- cut(imp_long$imputations[[i]]$InteresPoli_av, 
                           breaks=quantile(imp_long$imputations[[i]]$InteresPoli_av, c(0, .75, 1)),
                           include.lowest=TRUE)
  levels(imp_long$imputations[[i]]$InteresPoli_avF) <- c("Low", "High")
}
save(imp_long, file="imp_long.RData")
@


<<echo=FALSE, eval=TRUE, results='asis', warning=FALSE, message=FALSE, cache=T, fig.pos="h", fig.cap="Distribution of Individual Political Interest Average through Five Waves (2016-2021)", out.width="80%", fig.align ='center'>>=

###-- Figure D1: Distribution of Political Interest --###
barplot(prop.table(table(ell$InteresPoli_av)), border = NA, ylim=c(0,.2),
        xlab="Average Level of Political Interest", ylab="Percentage")
@
\newpage

<<echo=FALSE, eval=TRUE, results='asis', warning=FALSE, message=FALSE, cache=T, fig.pos='H'>>=

#Models
ab2_cm_lo <-pgmm(izqder ~ lag(izqder,1) +  mov_izq + ess + desempleo + practica + 
                  InteresPoli | lag(izqder, 2:99) + lag(mov_izq, 1:99), 
                data = subset(ell, ell$InteresPoli_avF=="Low"),
                index = c("idencuesta","time"), effect="twoways")
  
ab2_cm_hi <-pgmm(izqder ~ lag(izqder,1) + mov_izq + ess + desempleo + practica + 
                  InteresPoli | lag(izqder, 2:99) + lag(mov_izq, 1:99), 
                data = subset(ell, ell$InteresPoli_avF=="High"),
                index = c("idencuesta","time"), effect="twoways")
  
#AB1 imputado
ab2_imp_lo <- lapply(imp_long$imputations, function(x){
    pgmm(izqder ~ lag(izqder,1) + mov_izq + ess + desempleo  + practica + 
           InteresPoli | lag(izqder, 2:99) + lag(mov_izq, 1:99), 
         data = subset(x, InteresPoli_avF=="Low"),
         index = c("idencuesta","time"), effect="twoways")})
  
ab2_imp_hi <- lapply(imp_long$imputations, function(x){
    pgmm(izqder ~ lag(izqder,1) + mov_izq + ess + desempleo  + practica + InteresPoli | 
           lag(izqder, 2:99) + lag(mov_izq, 1:99), data = subset(x, InteresPoli_avF=="High"),
         index = c("idencuesta","time"), effect="twoways")})
  
texreg(l=list(extract.pgmm_R(ab2_cm_lo), extract.pgmm_R(ab2_cm_hi), 
              extract.pgmm_mi(ab2_imp_lo),  extract.pgmm_mi(ab2_imp_hi)),
       custom.header = list("Without MI" = 1:2, "With MI" = 3:4),
       custom.model.names = c("Low Interest", "High Interest", 
                                "Low Interest", "High Interest"),
       dcolumn = T, booktabs = T, use.packages = F, digits=3,
       scalebox = .9, float.pos = 'h!',
       custom.coef.map=list("lag(izqder, 1)"="Left-Right Scale$_{t-1}$",
                            "lag(mov_izq, 1)"="Soc. Mov. Assessment$_{t-1}$", 
                            "mov_izq"="Soc. Mov. Assessment$_{t}$", 
                            "ess"="Subjective Social Status$_{t}$", 
                            "desempleo"="Unemployed$_{t}$",
                            "practica"="Church Attendance$_{t}$", 
                            "InteresPoli"="Political Interest$_{t}$",
                            "3"="Wave 2018", "4"="Wave 2019", "5"="Wave 2020/1"),
       caption="Linear dynamic model (Arellano Bond) for political ideology with contemporaneous effects under sequential exogeneity for respondents with low and high average political interest. Estimations without and with multiple imputations")
@

\newpage

<<echo=FALSE, eval=TRUE, results='asis', warning=FALSE, message=FALSE, cache=T, fig.pos='H'>>=
  
########## Ab Models With Contemporaneous And Lagged Social Movement Assessment
load("imp_long.RData")
  
ab3_cm_lo <-pgmm(izqder ~ lag(izqder,1) +  lag(mov_izq,1) + mov_izq + ess + desempleo + 
                  practica + InteresPoli | lag(izqder, 2:99) + lag(mov_izq,2:99) + 
                lag(mov_izq, 1:99), 
                data = subset(ell, ell$InteresPoli_avF=="Low"),
                index = c("idencuesta","time"), effect="twoways")
  
ab3_cm_hi <-pgmm(izqder ~ lag(izqder,1) + lag(mov_izq,1) + mov_izq + ess + desempleo + 
                  practica + InteresPoli | lag(izqder, 2:99) + lag(mov_izq,2:99) + 
                lag(mov_izq, 1:99), 
                data = subset(ell, ell$InteresPoli_avF=="High"),
                index = c("idencuesta","time"), effect="twoways")
  
#AB1 imputado
ab3_imp_lo <- lapply(imp_long$imputations, function(x){
    pgmm(izqder ~ lag(izqder,1) + mov_izq + lag(mov_izq, 1) + ess + desempleo  + 
           practica + 
           InteresPoli | lag(izqder, 2:99) + lag(mov_izq,2:99) + 
           lag(mov_izq, 1:99), 
         data = subset(x, InteresPoli_avF=="Low"),
         index = c("idencuesta","time"), effect="twoways")})
  
ab3_imp_hi <- lapply(imp_long$imputations, function(x){
    pgmm(izqder ~ lag(izqder,1) + lag(mov_izq, 1) + mov_izq + ess + desempleo  + 
           practica + 
           InteresPoli | lag(izqder, 2:99) + lag(mov_izq,2:99) + lag(mov_izq, 1:99), 
         data = subset(x, InteresPoli_avF=="High"),
         index = c("idencuesta","time"), effect="twoways")}  )
  
texreg(l=list(extract.pgmm_R(ab3_cm_lo), extract.pgmm_R(ab3_cm_hi), 
              extract.pgmm_mi(ab3_imp_lo), extract.pgmm_mi(ab3_imp_hi)),
       custom.header = list("Without MI" = 1:2, "With MI" = 3:4),
       custom.model.names = c("Low Interest", "High Interest", 
                              "Low Interest", "High Interest"),
       dcolumn = T, booktabs = T, use.packages = F, digits=3,
       scalebox = .9, float.pos = "h!",
       custom.coef.map=list("lag(izqder, 1)"="Left-Right Scale$_{t-1}$",
                            "lag(mov_izq, 1)"="Soc. Mov. Assessment$_{t-1}$",
                            "mov_izq"="Soc. Mov. Assessment$_{t}$",
                            "ess"="Subjective Social Status$_{t}$",
                            "desempleo"="Unemployed$_{t}$",
                            "practica"="Church Attendance$_{t}$",
                            "InteresPoli"="Political Interest$_{t}$",
                            "3"="Wave 2018", "4"="Wave 2019", "5"="Wave 2020/1"),
       caption="Linear dynamic model (Arellano Bond) for political ideology with lagged and contemporaneous effects under sequential exogeneity for respondents with low and high average political interest. Estimations without and with multiple imputations")
@

\newpage

<<echo=FALSE, eval=FALSE, warning=FALSE, message=FALSE, fig.cap="Long-Run Effects of Social Movement Assessment on Political Ideology for Different Levels of Political Interest", fig.align ='center'>>=

### Code for Figure 2: Long-run effects plot (main article) ###

#Calculate long-run effects and SE's - All cases
source("long_run_effects.R")

##Long-run effects
lrun <- rbind(
  long_run(ab3_imp, "izq", "A) Full Sample", "Imputed"),
  long_run(ab3_cm, "izq", "A) Full Sample", "Not Imputed"),
  long_run(ab3_cm_lo, "izq", "C) Low Interest", "Not Imputed"),
  long_run(ab3_cm_hi, "izq", "B) High Interest", "Not Imputed"),
  long_run(ab3_imp_lo, "izq", "C) Low Interest", "Imputed"),
  long_run(ab3_imp_hi, "izq", "B) High Interest", "Imputed")
)

theme_set(theme_bw())
ggplot(lrun, aes(point, imputed)) + 
  geom_point(size=2) + 
  geom_linerange(aes(xmin = cilow95, xmax = cihigh95), linewidth = 0.5) +
  geom_linerange(aes(xmin = cilow90, xmax = cihigh90), linewidth = 1) +
  xlim(-2,0.5) + 
  facet_wrap(~sample, nc=3) + 
  geom_vline(xintercept = 0, lty=2, col="red") + 
  labs(x="Point Estimate with 90% and 95% Confidence Intervals", y="")+
  theme(axis.text.x = element_text(size = 10),
        axis.text.y = element_text(size = 12),
        axis.title.x = element_text(size = 15),
        strip.text.x = element_text(size = 13))
@


\medskip

\subsection{Robustness Tests}

\subsubsection{Linear Dynamic Models for Political Ideology under Alternative Missing Data Procedure}

In order to test the robustness of our estimations under different missing data processes, we have generated two additional sets of imputed data. First, we imputed political ideology only for individuals who declare ideological identification at least in two waves. Then, we repeated the process but only for people who placed themselves on the ideological scale at least three times during the period. Subsequently, we estimated the dynamic panel models. The results are displayed in the following tables and show high consistency to the original estimates:

\setcounter{table}{0} %%Renew count of tables

<<echo=FALSE, eval=TRUE, results='hide', warning=FALSE, message=FALSE, cache=T>>=

#Long Database: subset of individuals who place themselves at least twice 
ell2=ell
ell2 <- ell2 %>% group_by(idencuesta) %>% mutate(na_2 = paste0(izqder, collapse ="")) 
ell2$na_2 <- str_count(ell2$na_2, "NA")
ell2 = ell2 %>% dplyr::filter(na_2==0|na_2==1|na_2==2|na_2==3)
save(ell2, file="Elsoc_Long_2016_2021_REC_2.Rdata")

#Wide Dataset: respondents who declare left-right self-postion at least twice
load("Elsoc_Wide_2016_2021_REC.Rdata")
elw$pat2=with(elw, paste(izqder_w01,izqder_w02,izqder_w03,izqder_w04,izqder_w05))
elw$id.pat2 <- str_count(elw$pat2, "NA")
elw2 = elw %>% filter(id.pat2==0|id.pat2==1|id.pat2==2|id.pat2==3)
  
elw2_miss <- elw2[, names(elw2) %in% vars] 
elw2_miss$imputed <- ifelse(is.na(elw2_miss$izqder_w01), 1, 0)

#Set up imputation process
imp2 <- mice(elw2_miss, maxit = 0)#siempre 0 al inicio
predmat2 <- imp2$predictorMatrix #matriz de imputacion
for(i in 1:dim(predmat2)[1]) predmat2[i,] = 0 #relleno con 0
  
ivs1 <- c("edad_w01", "hombre_w01", "educF_w01", "int_Guillier02", "int_Pinera02", 
            "int_Sanchez02")
ivs2 <- c("practica_w", "InteresPoli_w", "mov_izq_w", "desempleo_w", 
            "ess_w", "confCara_w", "ViolCarab_w", "autori_w")
  
predmat2["izqder_w01",c(ivs1, paste0(ivs2,"01"))] = 1
predmat2["izqder_w02",c(ivs1,paste0(ivs2,"02"),"izqder_w01","mov_izq_w01")]=1
predmat2["izqder_w03",c(ivs1,paste0(ivs2,"03"),"izqder_w02","mov_izq_w02")]=1
predmat2["izqder_w04",c(ivs1,paste0(ivs2,"04"),"izqder_w03","mov_izq_w03")]=1
predmat2["izqder_w05",c(ivs1,paste0(ivs2,"05"),"izqder_w04","mov_izq_w04")]=1

meth2 = imp2$method
for(i in 1:length(meth2)) meth2[i] = ""
meth2["izqder_w01"] = "pmm"
meth2["izqder_w02"] = "pmm"
meth2["izqder_w03"] = "pmm"
meth2["izqder_w04"] = "pmm"
meth2["izqder_w05"] = "pmm"
#Force values of imputed izq-der within 0-10 range
post2 <- imp2$post
post2["izqder_w01"] <- "imp[[j]][, i] <- squeeze(imp[[j]][, i], c(0, 10))"
post2["izqder_w02"] <- "imp[[j]][, i] <- squeeze(imp[[j]][, i], c(0, 10))"
post2["izqder_w03"] <- "imp[[j]][, i] <- squeeze(imp[[j]][, i], c(0, 10))"
post2["izqder_w04"] <- "imp[[j]][, i] <- squeeze(imp[[j]][, i], c(0, 10))"
post2["izqder_w05"] <- "imp[[j]][, i] <- squeeze(imp[[j]][, i], c(0, 10))"
  
#Impute
imp2 <- mice(elw2_miss, m=10, meth=meth2, pred=predmat2, maxit = 100,
                post=post2, seed=4826)
  
##Create Completed Data Frame
elw2_comp <- mice::complete(imp2, "long", include=F)

#Save imputed data
save(elw2_comp, file="Elsoc_Wide_2016_2021_completed_2.Rdata")
@  

<<echo=FALSE, eval=TRUE, results='asis', warning=FALSE, message=FALSE, cache=T>>=
load("Elsoc_Long_2016_2021_REC_2.Rdata")
load("Elsoc_Wide_2016_2021_completed_2.Rdata")
# create an imputationList by splitting the tall dataset by imputation id
imp_list2 <- imputationList(split(elw2_comp, elw2_comp$.imp))
  
vv <- c("practica","desempleo", "confCara", "ViolCarab","InteresPoli", "polengage", 
          "izqder", "autori", "mov_izq", "ess")

imputations2 <-lapply(imp_list2$imputations, function(df) {
    reshape(df, varying=lapply(vv, function(x) paste0(x,"_w0", 1:5)),
            v.names = vv, direction="long", idvar="idencuesta", times=1:5)})
imp_long2 <- list(imputations2); names(imp_long2) <- c("imputations")


#Arellano Bond 1 - lag Social Movements Assessment (original data)
ab1_cm2 <-pgmm(izqder ~ lag(izqder,1) + lag(mov_izq,1) + ess + desempleo + practica + InteresPoli | 
                lag(izqder, 2:99) + lag(mov_izq, 2:99), 
              data = ell2, index = c("idencuesta","time"), 
              effect="twoways", transformation="d", model="onestep")

#Arellano Bond 1 - lag Social Movements Assessment (imputed data)
ab1_imp2 <- lapply(imp_long2$imputations, function(x){
  pgmm(izqder ~ lag(izqder,1) + lag(mov_izq,1) + ess + desempleo + practica + InteresPoli | 
         lag(izqder, 2:99) + lag(mov_izq, 2:99), 
       data = x, index = c("idencuesta","time"), 
       effect="twoways", transformation="d", model="onestep")})

#Arellano Bond 2 - Contemporaneous Social Movements Assessment (original data)
ab2_cm2 <-pgmm(izqder ~ lag(izqder,1) + mov_izq + ess + desempleo + practica + InteresPoli | 
                lag(izqder, 2:99) + lag(mov_izq, 1:99), 
              data = ell2, index = c("idencuesta","time"), 
              effect="twoways", transformation="d", model="onestep")

#Arellano Bond 2 - Contemporaneous Social Movements Assessment (imputed data)
ab2_imp2 <- lapply(imp_long2$imputations, function(x){
  pgmm(izqder ~ lag(izqder,1) + mov_izq + ess + desempleo + practica + InteresPoli | 
         lag(izqder, 2:99) + lag(mov_izq, 1:99), 
       data = x, index = c("idencuesta","time"), 
      effect="twoways", transformation="d", model="onestep")})


#Arellano Bond 3 - Lagged and Contemporaneous Social Movements Assessment (original data)
ab3_cm2 <-pgmm(izqder ~ lag(izqder,1) + mov_izq + lag(mov_izq,1) + ess + desempleo + 
               practica + InteresPoli | 
               lag(izqder, 2:99) + lag(mov_izq, 1:99) + lag(mov_izq, 2:99), 
             data = ell2, index = c("idencuesta","time"), 
             effect="twoways", model="onestep", transformation = "d")

#Arellano Bond 3 - Lagged and Contemporaneous Social Movements Assessment (imputed data)
ab3_imp2 <- lapply(imp_long2$imputations, function(x){
  pgmm(izqder ~ lag(izqder,1) + mov_izq + lag(mov_izq,1) + ess + desempleo + 
         practica + InteresPoli | 
         lag(izqder, 2:99) + lag(mov_izq, 1:99) + lag(mov_izq, 2:99), 
       data = x, index = c("idencuesta","time"), 
       effect="twoways", model="onestep", transformation = "d")})

texreg(l=list(extract.pgmm_R(ab1_cm2),extract.pgmm_R(ab2_cm2),extract.pgmm_R(ab3_cm2), 
             extract.pgmm_mi(ab1_imp2),extract.pgmm_mi(ab2_imp2),extract.pgmm_mi(ab3_imp2)),
       custom.model.names = c("1","2","3","4","5","6"),
       custom.header = list("Without MI"=1:3,"With MI"=4:6),
       dcolumn = T, booktabs = T, use.packages = F,
       scalebox = .8, float.pos = "H", digits=3,
       include.wald=F, include.wald.td=F,
       custom.coef.map=list("lag(izqder, 1)"="Left-Right Scale$_{t-1}$", 
                              "lag(mov_izq, 1)"="Social Movement Assessment$_{t-1}$", 
                              "mov_izq"="Social Movement Assessment$_{t}$", 
                              "ess"="Subjective Social Status$_{t}$", 
                              "desempleo"="Unemployed$_{t}$",
                              "practica"="Church Attendance$_{t}$", 
                              "InteresPoli"="Political Interest$_{t}$",
                              "3"="Wave 2018", "4"="Wave 2019", "5"="Wave 2020/1"),
       custom.note = "%stars. Standard errors in parentheses. MI = Multiple imputation.",
       caption="Dynamic Panel Models (Arellano-Bond Estimator) for Left-Right Self-Placement, Under Sequential Exogeneity. Original and Imputed Data. Data Include Only Individuals Who Declare Political Ideology in at Least Two Waves.")
@
\newpage

<<echo=FALSE, eval=TRUE, results='hide',  warning=FALSE, message=FALSE, cache=TRUE>>=

#Long Database: subset of individuals who place themselves at least three times 
ell3=ell
ell3 <- ell3 %>% group_by(idencuesta) %>% mutate(na_3 = paste0(izqder, collapse =""))
ell3$na_3 <- str_count(ell3$na_3, "NA")
ell3 = ell3 %>% dplyr::filter(na_3==0|na_3==1|na_3==2)
save(ell3, file="Elsoc_Long_2016_2021_REC_3.Rdata")

#Wide Dataset: respondents who declare left-right self-postion at least twice
load("Elsoc_Wide_2016_2021_REC.Rdata")
elw3=elw
elw3$pat3=with(elw3, paste(izqder_w01,izqder_w02,izqder_w03,izqder_w04,izqder_w05))
elw3$id.pat3 <- str_count(elw3$pat3, "NA")
elw3 = elw3 %>% filter(id.pat3==0|id.pat3==1|id.pat3==2)
  
elw3_miss <- elw3[, names(elw3) %in% vars] 
elw3_miss$imputed <- ifelse(is.na(elw3_miss$izqder_w01), 1, 0)

#Set up imputation process
imp3 <- mice(elw3_miss, maxit = 0)#siempre 0 al inicio
predmat3 <- imp3$predictorMatrix #matriz de imputacion
for(i in 1:dim(predmat3)[1]) predmat3[i,] = 0 #relleno con 0
  
ivs1 <- c("edad_w01", "hombre_w01", "educF_w01", "int_Guillier02", "int_Pinera02", 
            "int_Sanchez02")
ivs2 <- c("practica_w", "InteresPoli_w", "mov_izq_w", "desempleo_w", 
            "ess_w", "confCara_w", "ViolCarab_w", "autori_w")
  
predmat3["izqder_w01",c(ivs1, paste0(ivs2,"01"))] = 1
predmat3["izqder_w02",c(ivs1,paste0(ivs2,"02"),"izqder_w01","mov_izq_w01")]=1
predmat3["izqder_w03",c(ivs1,paste0(ivs2,"03"),"izqder_w02","mov_izq_w02")]=1
predmat3["izqder_w04",c(ivs1,paste0(ivs2,"04"),"izqder_w03","mov_izq_w03")]=1
predmat3["izqder_w05",c(ivs1,paste0(ivs2,"05"),"izqder_w04","mov_izq_w04")]=1

meth3 = imp3$method
for(i in 1:length(meth3)) meth3[i] = ""
meth3["izqder_w01"] = "pmm"
meth3["izqder_w02"] = "pmm"
meth3["izqder_w03"] = "pmm"
meth3["izqder_w04"] = "pmm"
meth3["izqder_w05"] = "pmm"
#Force values of imputed izq-der within 0-10 range
post3 <- imp3$post
post3["izqder_w01"] <- "imp[[j]][, i] <- squeeze(imp[[j]][, i], c(0, 10))"
post3["izqder_w02"] <- "imp[[j]][, i] <- squeeze(imp[[j]][, i], c(0, 10))"
post3["izqder_w03"] <- "imp[[j]][, i] <- squeeze(imp[[j]][, i], c(0, 10))"
post3["izqder_w04"] <- "imp[[j]][, i] <- squeeze(imp[[j]][, i], c(0, 10))"
post3["izqder_w05"] <- "imp[[j]][, i] <- squeeze(imp[[j]][, i], c(0, 10))"
  
#Impute
imp3 <- mice(elw3_miss, m=10, meth=meth3, pred=predmat3, maxit = 100,
                post=post3, seed=4826)
  
##Create Completed Data Frame
elw3_comp <- mice::complete(imp3, "long", include=F)

#Save imputed data
save(elw3_comp, file="Elsoc_Wide_2016_2021_completed_3.Rdata")
@

<<echo=FALSE, eval=TRUE, results='asis', warning=FALSE, message=FALSE, cache=TRUE>>=
load("Elsoc_Long_2016_2021_REC_3.Rdata")
load("Elsoc_Wide_2016_2021_completed_3.Rdata")

# create an imputationList by splitting the tall dataset by imputation id
imp_list3 <- imputationList(split(elw3_comp, elw3_comp$.imp))
  
vv <- c("practica","desempleo", "confCara", "ViolCarab","InteresPoli", "polengage", 
          "izqder", "autori", "mov_izq", "ess")

imputations3 <-lapply(imp_list3$imputations, function(df) {
    reshape(df, varying=lapply(vv, function(x) paste0(x,"_w0", 1:5)),
            v.names = vv, direction="long", idvar="idencuesta", times=1:5)})
imp_long3 <- list(imputations3); names(imp_long3) <- c("imputations")


#Arellano Bond 1 - lag Social Movements Assessment (original data)
ab1_cm3 <-pgmm(izqder ~ lag(izqder,1) + lag(mov_izq,1) + ess + desempleo + practica + InteresPoli | 
                lag(izqder, 2:99) + lag(mov_izq, 2:99), 
              data = ell3, index = c("idencuesta","time"), 
              effect="twoways", transformation="d", model="onestep")

#Arellano Bond 1 - lag Social Movements Assessment (imputed data)
ab1_imp3 <- lapply(imp_long3$imputations, function(x){
  pgmm(izqder ~ lag(izqder,1) + lag(mov_izq,1) + ess + desempleo + practica + InteresPoli | 
         lag(izqder, 2:99) + lag(mov_izq, 2:99), 
       data = x, index = c("idencuesta","time"), 
       effect="twoways", transformation="d", model="onestep")})

#Arellano Bond 2 - Contemporaneous Social Movements Assessment (original data)
ab2_cm3 <-pgmm(izqder ~ lag(izqder,1) + mov_izq + ess + desempleo + practica + InteresPoli | 
                lag(izqder, 2:99) + lag(mov_izq, 1:99), 
              data = ell3, index = c("idencuesta","time"), 
              effect="twoways", transformation="d", model="onestep")

#Arellano Bond 2 - Contemporaneous Social Movements Assessment (imputed data)
ab2_imp3 <- lapply(imp_long3$imputations, function(x){
  pgmm(izqder ~ lag(izqder,1) + mov_izq + ess + desempleo + practica + InteresPoli | 
         lag(izqder, 2:99) + lag(mov_izq, 1:99), 
       data = x, index = c("idencuesta","time"), 
      effect="twoways", transformation="d", model="onestep")})


#Arellano Bond 3 - Lagged and Contemporaneous Social Movements Assessment (original data)
ab3_cm3 <-pgmm(izqder ~ lag(izqder,1) + mov_izq + lag(mov_izq,1) + ess + desempleo + 
               practica + InteresPoli | 
               lag(izqder, 2:99) + lag(mov_izq, 1:99) + lag(mov_izq, 2:99), 
             data = ell3, index = c("idencuesta","time"), 
             effect="twoways", model="onestep", transformation = "d")

#Arellano Bond 3 - Lagged and Contemporaneous Social Movements Assessment (imputed data)
ab3_imp3 <- lapply(imp_long3$imputations, function(x){
  pgmm(izqder ~ lag(izqder,1) + mov_izq + lag(mov_izq,1) + ess + desempleo + 
         practica + InteresPoli | 
         lag(izqder, 2:99) + lag(mov_izq, 1:99) + lag(mov_izq, 2:99), 
       data = x, index = c("idencuesta","time"), 
       effect="twoways", model="onestep", transformation = "d")})

texreg(l=list(extract.pgmm_R(ab1_cm3),extract.pgmm_R(ab2_cm3),extract.pgmm_R(ab3_cm3), 
             extract.pgmm_mi(ab1_imp3),extract.pgmm_mi(ab2_imp3),extract.pgmm_mi(ab3_imp3)),
       custom.model.names = c("1","2","3","4","5","6"),
       custom.header = list("Without MI"=1:3,"With MI"=4:6),
       dcolumn = T, booktabs = T, use.packages = F,
       scalebox = .8, float.pos = "H", digits=3,
       include.wald=F, include.wald.td=F,
       custom.coef.map=list("lag(izqder, 1)"="Left-Right Scale$_{t-1}$", 
                              "lag(mov_izq, 1)"="Social Movement Assessment$_{t-1}$", 
                              "mov_izq"="Social Movement Assessment$_{t}$", 
                              "ess"="Subjective Social Status$_{t}$", 
                              "desempleo"="Unemployed$_{t}$",
                              "practica"="Church Attendance$_{t}$", 
                              "InteresPoli"="Political Interest$_{t}$",
                              "3"="Wave 2018", "4"="Wave 2019", "5"="Wave 2020/1"),
       custom.note = "%stars. Standard errors in parentheses. MI = Multiple imputation.",
       caption="Dynamic Panel Models (Arellano-Bond Estimator) for Left-Right Self-Placement, Under Sequential Exogeneity. Original and Imputed Data. Data Include Only Individuals Who Declare Political Ideology in at Least Three Waves.")
@
\newpage


\subsubsection{Cross-Lagged Panel Models with Fixed Effects Estimated by ML-SEM (Allison, Williams and Moral-Benito, 2017)}  

As mentioned in the main article, we also got estimates by maximum likelihood (ML) and structural equation modeling (SEM), following what was proposed by Allison, Williams, and Moral-Benito (2017). Table E3 displays the results, which are consistent and similar to those obtained with the Arellano-Bond estimator, except for the omission of the time dummy coefficients, which is a limitation of the technique.

<<echo=FALSE, eval=TRUE, results='asis', warning=FALSE, message=FALSE, cache=T>>=
### Allison, William & Moral-Benito Models ###
source("extract_texreg_dpm.R")##read results

#Complete obs
dpm_cm_1 <- dpm(izqder ~ pre(mov_izq) + 
                   ess + desempleo + practica + InteresPoli, error.inv=T,
                 data = panel_data(ell, id="idencuesta", wave="time"))

dpm_cm_2 <- dpm(izqder ~ pre(lag(mov_izq)) + 
                   ess + desempleo + practica + InteresPoli, 
                 data = panel_data(ell, id="idencuesta", wave="time"))

dpm_cm_3 <- dpm(izqder ~ pre(mov_izq) + pre(lag(mov_izq)) + 
                   ess + desempleo + practica + InteresPoli, 
                 data = panel_data(ell, id="idencuesta", wave="time"))

#Imputed data
dpm_imp_1 <- lapply(imp_long$imputations, function(x){
  dpm(izqder ~ pre(mov_izq) + 
        ess + desempleo + practica + InteresPoli, 
      data = panel_data(x, id="idencuesta", wave="time"))
})

dpm_imp_2 <- lapply(imp_long$imputations, function(x){
  dpm(izqder ~ pre(lag(mov_izq)) + 
        ess + desempleo + practica + InteresPoli, 
      data = panel_data(x, id="idencuesta", wave="time"))
})

dpm_imp_3 <- lapply(imp_long$imputations, function(x){
  dpm(izqder ~ pre(mov_izq) + pre(lag(mov_izq)) + 
        ess + desempleo + practica + InteresPoli, 
      data = panel_data(x, id="idencuesta", wave="time"))
})


#Results
texreg(l=list(extract_dpm(dpm_cm_1),extract_dpm(dpm_cm_2),extract_dpm(dpm_cm_3),
              extract_dpm(dpm_imp_1),extract_dpm(dpm_imp_2),extract_dpm(dpm_imp_3)),
       custom.model.names = c("1","2","3","4","5","6"),
       custom.header = list("Without MI"=1:3,"With MI"=4:6),
       dcolumn = T, booktabs = T, use.packages = F,
       scalebox = .8, float.pos = "H", digits=3,
       include.wald=F, include.wald.td=F,
       custom.coef.map=list("izqder (t - 1)"="Left-Right Scale$_{t-1}$", 
                              "mov_izq (t - 1)"="Social Movement Assessment$_{t-1}$", 
                              "mov_izq"="Social Movement Assessment$_{t}$", 
                              "ess"="Subjective Social Status$_{t}$", 
                              "desempleo"="Unemployed$_{t}$",
                              "practica"="Church Attendance$_{t}$", 
                              "InteresPoli"="Political Interest$_{t}$"),
       custom.note = "%stars. Standard errors in parentheses. MI = Multiple imputation.",
       caption="Cross-Lagged Panel Models with Fixed Effects using ML-SEM (Allison, Williams and Moral-Benito, 2017). Data Include Only Individuals Who Declare Political Ideology at Least in One Wave.")

@


\newpage

\subsection{References}

\begin{itemize}
\renewcommand\labelitemi{--}
\item Allison, P. D., Williams, R., \& Moral-Benito, E. (2017). Maximum likelihood for cross-lagged panel models with fixed effects. Socius, 3: 1–17. \\
https://doi.org/10.1177/2378023117710578
\item Austin, P. C., White, I. R., Lee, D. S., \& van Buuren, S. (2021). Missing data in clinical research: a tutorial on multiple imputation. Canadian Journal of Cardiology, 37(9), 1322-1331. https://doi.org/10.1016/j.cjca.2020.11.010
\item Bargsted, M. A., \& Somma, N. M. (2016). Social cleavages and political dealignment in contemporary Chile, 1995–2009. Party Politics, 22(1), 105–124.\\ 
https://doi.org/10.1177/1354068813514865
\item Hardt, J., Herke, M., \& Leonhart, R. (2012). Auxiliary variables in multiple imputation in regression with missing X: a warning against including too many in small sample research. BMC medical research methodology, 12(1), 1-13.\\
https://doi.org/10.1186/1471-2288-12-184
\item Honaker, J., \& King, G. (2010). What to do about missing values in time‐series cross‐section data. American journal of political science, 54(2), 561-581.\\ https://doi.org/10.1111/j.1540-5907.2010.00447.x
\item Van Buuren S, \& Groothuis-Oudshoorn K (2011). “mice: Multivariate Imputation by Chained Equations in R.” Journal of Statistical Software, 45(3), 1-67.\\
https://doi.org/10.18637/jss.v045.i03.
\item Von Hippel, P. T. (2007). Regression with missing Ys: an improved strategy for analyzing multiply imputed data. Sociological Methodology, 37(1), 83-117.\\ 
https://doi.org/10.1111/j.1467-9531.2007.00180.x
\item Zechmeister, E. J., \& Corral, M. (2013). Individual and Contextual Constraints on Ideological Labels in Latin America. Comparative Political Studies, 46(6), 675–701. https://doi.org/10.1177/0010414012463880
\end{itemize}

\end{document}
    
